<?php
/**
 * Created by xuan.
 * Author: xuan
 * Date: 2018/8/3
 * Time: 18:24
 */

namespace app\api\model;
use think\Db;

class Payment extends BaseModel
{	
	protected $table = 'payment';
	
	public static function selectOnePaymentByID($id){
		$data = model("Payment")->where(array("id"=>$id))->find();
		return $data;
	}
	
	public static function selectOnePaymentByIdMid($all){
		$data = model("Payment")->where(array("id"=>$all['id'],"mid"=>$all['mid']))->find();
		return $data;
	}
	
	public static function paymentListsByMid($mid){
		$data = model("Payment")->where(array("mid"=>$mid))->select();
		return $data;
	}
	
	public static function addOnePayment($all)
    {
		$data = Payment::create([
			'ifdefault' => $all['ifdefault'],
			'mid' => $all['mid'],
			'paytype' => $all['paytype'],
			'name' => $all['name'],
			'addr' => $all['addr'],
			'num' => $all['num'],
			'addtime' => date('Y-m-d H:i:s',time()),
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		  
		return $data;
    }
	
	public static function updOnePayment($all)
    {
		$data=Db::name('Payment')-> where('id',$all['id'])->update([
			'ifdefault' => $all['ifdefault'],
			'paytype' => $all['paytype'],
			'name' => $all['name'],
			'addr' => $all['addr'],
			'num' => $all['num'],
			'updatetime' => date('Y-m-d H:i:s',time())
		]);
		return $data;
    }
	
	public static function delOnePayment($id)
    {
		$data=Db::name('Payment')-> where('id',$id)->delete();
		return $data;
    }
	
	public static function updOnePaymentDef($all)
    {
		$data2=Db::name('Payment')-> where('mid',$all['mid'])->update(['ifdefault' => 2,'updatetime' => date('Y-m-d H:i:s',time())]);
		$data=Db::name('Payment')-> where(array("id"=>$all['id'],"mid"=>$all['mid']))->update(['ifdefault' => 1,'updatetime' => date('Y-m-d H:i:s',time())]);
		return $data;
    }
}